package timelist

import (
	"gitee.com/zhongguo168a/gocodes/myx/pool"
	"strconv"
)

// todo: 测试
var pools = pool.NewPool()

func init() {
	pools.SetCreator(func(args ...interface{}) interface{} {
		return NewTimeItem()
	})
}

func CreateTimerItem() *TimeItem {
	return NewTimeItem()
	//return pools.GetOrNewItem().(*TimeItem)
}

//func CreateTimerItem() *TimerItem {
//	return NewTimerItem()
//}

type ITimeHandler interface {
	// 更新时间集合
	UpdateTimerSet(ctx interface{}, createParams, updateParams []interface{})
}

type ITimeHost interface {
	//GetFactoryLink() *factory.Link
}

func NewTimeItem() (obj *TimeItem) {
	obj = &TimeItem{}
	return
}

type TimeItem struct {
	// 识别号
	Id int
	// 结束时间
	Complete int
	// 处理函数的对象
	//Target *factory.Link
	Target interface{}
	// 处理函数的参数
	CreateParams []interface{}
	UpdateParams []interface{}
	// 是否已经清除掉的标记
	Removed bool
	//
	Scale float64
	//
	DebugTag string
}

func (item *TimeItem) Dispose() {
	item.Target = nil
	item.CreateParams = nil
	item.UpdateParams = nil
}

func (item *TimeItem) Reset() {
	if item == nil {
		return
	}
	item.Target = nil
	item.CreateParams = []interface{}{}
	item.UpdateParams = []interface{}{}
	item.Scale = 1.0
	item.Complete = 0
	item.Id = 0
	item.Removed = true
}

func (item *TimeItem) String() string {
	return "Timer[" + strconv.Itoa(item.Complete) + "]"
}
